package com.dyz.leetcode._20_dynamicProgramming._213;

public class _213_rob01 {
    public int rob(int[] nums) {
        if(nums.length==1){return nums[0];}
        int n = nums.length;
        int notRobLastHouse = rob(nums,0, n-1);
        int notRobFirstHouse = rob(nums, 1, n);
        return Math.max(notRobLastHouse, notRobFirstHouse);



    }
    //动态规划+压缩
    public int rob(int[] nums, int start, int end){
        if(nums.length==1){return nums[0];}

        int prevMax = 0;
        int currMax = 0;
        for (int i = start; i <end ; i++) {
            int tmpMax = Math.max(currMax, prevMax+nums[i]);
            prevMax = currMax;
            currMax = tmpMax;
        }
        return currMax;
    }
}
